<?php
class Core_Backend_Component_Global_Controller_Module extends Dcmp_Component_Controller {

    protected function indexAction($pageindex = 1,$pagesize=20,$sort='id',$dir='asc'){
        $this->getHistory()->record();
        $collection = App::getModel('global/collection_module')
                        ->sortBy($sort, $dir)
                        ->pagination($pageindex,$pagesize)
                        ->load();
        $record = $collection->loadCount();
        return $this->viewResult(array('list'=>$collection,'records'=>$record));
    }

    protected function assignAction($id){
        $model = App::getModel('global/module')->load($id);
        $areas = App::getModel('global/collection_area')->load();
        return $this->viewResult(array('model'=>$model,'areas'=>$areas));
    }

    protected function savePostAction(){
        $data = $this->getRequest()->getForm('assign');
        App::getModel('global/module')
                ->load($data['id'])
                ->assignArea($data['area_ids']);
        return $this->redirectResult($this->getHistoryUrl('global/module/index'));
    }
}
